package marcus.tree;

import java.util.LinkedList;
import java.util.Queue;

public class BinaryTreePrinter {
	public static void preOrder(BinaryNode node){
		if (node == null){
			return;
		}
		System.out.println(node.getValue());
		preOrder(node.getLeftNode());
		preOrder(node.getRightNode());
	}
	
	public static void inOrder(BinaryNode node){
		if (node == null){
			return;
		}
		inOrder(node.getLeftNode());
		System.out.println(node.getValue());
		inOrder(node.getRightNode());
	}

	public static void postOrder(BinaryNode node){
		if (node == null){
			return;
		}
		postOrder(node.getLeftNode());
		postOrder(node.getRightNode());
		System.out.println(node.getValue());
	}
	
	public static void breadthOrder(BinaryNode node){
		Queue<BinaryNode> nodes  = new LinkedList<BinaryNode>();
		if (node == null){
			return;
		}
		nodes.offer(node);
		
		while (nodes.peek() != null){
			BinaryNode n = nodes.poll();
			System.out.println(n.getValue());
			
			if (n.getLeftNode() != null){
				nodes.offer(n.getLeftNode());
			}
			if (n.getRightNode() != null){
				nodes.offer(n.getRightNode());
			}
		}
	}
	
	
}
